package com.goliathonline.android.kegbot;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class API {

	private String _host;
	private int _port = 80;
	private String _baseURL;
	
	public void SetHost(String host)
	{
		_host = host;
		_baseURL = _host + "/api/";
	}
	
	public void SetHost(String host, int port)
	{
		_host = host;
		_port = port;
		_baseURL = "http://" + _host + ":" + _port + "/api/";
	}

	public String GetLast10()
	{
		try {
			URL apiURL = new URL(_baseURL + "last-drinks/");
			URLConnection conn = apiURL.openConnection();
			InputStream is = conn.getInputStream();
			InputStreamReader reader = new InputStreamReader(is);
			StringBuffer buffer = new StringBuffer();
			int ch;
			while(reader.ready())
			{
				ch = reader.read(); 
				buffer.append((char)ch);
			}
			return buffer.toString();
		} catch (Exception e) {
			return e.toString();
		}
		
	}
}
